(function(){
    let totop = document.getElementById("backtotop");
    let timer
    totop.onclick = function(){
        clearInterval(timer)
        timer = setInterval(() => {
            document.documentElement.scrollTop -= 150;

            if (document.documentElement.scrollTop <= 0) {
                clearInterval(timer);
            }
        }, 20);
    }

    //监听页面的滚动
    window.onscroll = function(){
        //卷动值
        let scrollTop = document.documentElement.scrollTop ||window.scrollY;

        if (scrollTop == 0) {
            totop.style.display = "none";
        }else{
            totop.style.display = "block";
        }
    }
})();
